import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Random;

import common.SQLCall;

public class PopulateExam
{
	final static int TOTAL = 10;
	Connection conn;
	Generate sg;
	ArrayList<Integer> users;
	Random rnd = new Random();

	public static void main(String[] args)
	{
		PopulateExam pop = new PopulateExam();
		try
		{
			pop.connect();
		
			pop.setup();
			pop.generate();

			pop.close();
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

	public PopulateExam()
	{

	}

	public PopulateExam(Connection c)
	{
		conn = c;
	}

	public void connect() throws SQLException
	{
		DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
		conn = DriverManager.getConnection(
				"jdbc:oracle:thin:@146.187.134.17:1542:oracle10g", "cscd494",
				"R3tral435");

	}

	public void setup()
	{
		users = SQLCall.getApeUsers(conn);

		sg = new Generate(conn);
	}

	public void close() throws SQLException
	{
		conn.close();
	}

	public void generate() throws SQLException
	{
		for (int i = 0; i < TOTAL; i++)
		{
			int author = users.get(rnd.nextInt(users.size()));
			int id = SQLCall.getNextSeq(conn, "exam_s1");
			RandomDate rd = new RandomDate();

			System.out.println("id: " + id);
			System.out.println("author: " + author);
			
			SQLCall.getQuestionManager(conn).reset();

			sg.generate(rd.next(-1), rd.next(1), author);

		}
	}
}
